function $(a) {
  return document.querySelector(a);
}
var userId = localStorage.getItem("userId");
console.log(userId);
if (userId == null) {
  window.location.href = "/index";
}
// 退出登录
$(".exit").onclick = function () {
  var x = 1;
  if ((x = 1)) {
    console.log(x);
    $(".form-pop").querySelector("p").innerHTML = "你确定要退出吗？";
    $(".pop-box").style.display = "block";
    console.log();
    $(".submit-pop1").onclick = function () {
      axios({
        url: "/logout",
        method: "post",
      })
        .then(function (data) {
          console.log(data);
          console.log("退出账号成功！！！");
          window.localStorage.removeItem("userId");
          // alert('退出账号')
          window.location.href = "/index";
        })
        .catch(function (error) {
          console.log(error);
          console.log("失败");
        });
      $(".pop-box").style.display = "none";
    };
    $(".submit-pop2").onclick = function () {
      $(".pop-box").style.display = "none";
    };
    $(".back-pop").onclick = function () {
      $(".pop-box").style.display = "none";
    };
  }
};

var z = 1;

$(".bar").onclick = function () {
  z++;
  var b = $(".nav").querySelectorAll("b");
  var h4 = $(".nav").querySelector("h4");
  var a = $(".nav").querySelectorAll("a");
  if (z % 2 == 0) {
    $(".main-nav").style.width = "50px";
    $(".main-nav").querySelector("img").style.display = "none";
    $(".pp1").style.display = "none";
    h4.style.display = "none";
    for (let i = 0; i < b.length; i++) {
      b[i].style.display = "none";
      a[i].style.fontSize = "18px";
    }
  } else {
    $(".main-nav").style.width = "240px";
    $(".main-nav").querySelector("img").style.display = "";
    $(".pp1").style.display = "inline-block";
    h4.style.display = "";
    for (let i = 0; i < b.length; i++) {
      b[i].style.display = "";
      a[i].style.fontSize = "14px";
    }
  }
};

axios({
  method: "get",
  url: "/user/findUserById",
  params: {
    userId: userId,
  },
})
  .then(function (data) {
    let list = data.data.data.object;
    console.log(data.data.data.object);
    $(".imghead").src = list.src == "未上传" ? imgsrc : list.src;
    $(".username").innerHTML = list.account;

    //   ================================================
    //   $('.user1-account').innerHTML = list.account==null?'无':list.account;
    //   $('.user1-nickname').innerHTML = list.nickname==null?'无':list.nickname;
    //   $('.user1-age').innerHTML = list.age==null?'无':list.age;
    //   $('.user1-email').innerHTML = list.email==null?'无':list.email;
    //   $('.user1-vip').innerHTML = '管理员';
    //   $('.user1-sex').innerHTML = list.sex==null?'无':list.sex;

    $(".user1-account").innerHTML = list.account == null ? "无" : list.account;
    $(".user1-nickname").innerHTML =
      list.nickname == null ? "无" : list.nickname;
    $(".user1-age").innerHTML = list.age == null ? "无" : list.age;
    $(".user1-email").innerHTML = list.email == null ? "无" : list.email;
    if (list.vip == 1) {
      $(".user1-vip").innerHTML = "会员";
    } else if (list.vip == 0) {
      $(".user1-vip").innerHTML = "普通用户";
    } else {
      $(".user1-vip").innerHTML = "管理员";
    }
    $(".user1-sex").innerHTML = list.sex == null ? "无" : list.sex;
    $(".user1-signInPoint").innerHTML =
      list.signInPoint == null ? "无" : list.signInPoint;
    $(".user1-vipTime").innerHTML =
      list.vipTime == null
        ? "无"
        : Math.floor(list.vipTime / 60 / 60 / 24) + "天";
  })
  .catch((err) => {
    console.log(err);
  });

function popup(a, b, c) {
  a.addEventListener("click", function () {
    b.style.display = "block";
  });
  c.addEventListener("click", function () {
    b.style.display = "none";
  });
}

$(".admin-user").onclick = function () {
  console.log(1);
};
popup($(".admin-user"), $(".user1-box"), $(".back01"));
